package com.dq.controller.op.opmerchant;

import com.dq.exception.customException.AdminException;
import com.dq.controller.op.opmerchant.in.query.IntegralQuery;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.dq.domain.sys.user.Integral;
import com.dq.service.AllService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author heshuaijun
 * @date 2019/9/1820:56
 */
@Api(description = "后台会员积分记录管理")
@RestController
@RequestMapping("/sys/integral")
public class IntegralController extends AllService {


    @ApiOperation("所有会员列表")
    @PostMapping("/all")
    @RequiresPermissions("sys:integral:all")
    public Vo all() {
        //查询列表数据
        List<Integral> userlist = integralRepository.findAll();
        return new Vo(VO.toVOCollection(userlist, false));
    }

    @ApiOperation("根据条件检索会员列表")
    @PostMapping("/list")
    @RequiresPermissions("sys:integral:list")
    public Vo list(@RequestBody IntegralQuery integralQuery) throws AdminException {

        Map<String, Object> query = integralQuery.parseMap();
        List<Integral> userList = dao.find(dao.queryAdminHql(Integral.class, query), query);
        integralQuery.format();
        PageHelper.startPage(integralQuery.getPage(), integralQuery.getSize());
        PageInfo pageInfo = new PageInfo((List<Integral.Vo>) VO.toVOCollection(userList));
        pageInfo.setTotal(dao.count(dao.countAdminHql(Integral.class, query), query));
        return new Vo(pageInfo);
    }
}
